
#pragma once

using namespace NUnit::Framework;

#include "Common/Math.h"
#include "Common/Strings.h"

namespace strings
{
	[TestFixture]
	public ref class CastTests
	{
		public:
			//Tests int<->string casting.
			[Test]
			void intTests()
			{
				try
				{
					ttg::math::int32 iv32;
					ttg::math::int64 iv64;
					//Direct casting.
					Assert::AreEqual(true, ttg::strings::isInt("42", iv32) && iv32 == 42,
									 "\"42\" != 42");
					Assert::AreEqual(false, ttg::strings::isInt("answer42", iv32),
									 "\"answer42\" == 42");
					Assert::AreEqual(true, ttg::strings::isInt("42", iv64) && iv64 == 42,
									 "\"42\" != 42");
					Assert::AreEqual(false, ttg::strings::isInt("answer42", iv64),
									 "\"answer42\" == 42");
					//To and from casting.
					Assert::AreEqual(42, ttg::strings::toInt32(ttg::strings::toString(42)),
									 "42 != 42");
					Assert::AreEqual(42, (int)ttg::strings::toInt64(ttg::strings::toString(42)),
									 "42 != 42");
					//Wrong values casting.
					try
					{
						iv32 = ttg::strings::toInt32("ttgLib");
						Assert::Fail("OMG! ttgLib is int!");
					}
					catch (ttg::Error &) {}
				}
				catch (ttg::Error &err)
				{ Assert::Fail(gcnew System::String(err.toString())); }
			}
	};
}
